// 开始
module.exports = {
  msgInfo: (obj) => {
    if (obj === undefined) {
      obj = {
        type: true, // 是否自动关闭
        mask: true, // 是否打开遮罩
        text: '操作成功'
      }
    };
    if (document.getElementById('layerId') != null) return false
    const bodyMain = document.body
    if (obj.mask !== false) {
      if (document.getElementById('layerMaskId') != null) return false
      const layerMask = document.createElement('div')
      layerMask.setAttribute('id', 'layerMaskId')
      layerMask.classList.add('layerMainMask')
      bodyMain.appendChild(layerMask)
    }
    const layerMain = document.createElement('div')
    const layerSpan = document.createElement('span')
    const layerText = document.createTextNode(obj.text)
    layerMain.setAttribute('id', 'layerId')
    layerMain.classList.add('layerMainMsg')
    layerMain.classList.add('layer-anim')
    bodyMain.appendChild(layerMain)
    layerMain.appendChild(layerSpan)
    layerSpan.appendChild(layerText)
    if (obj.type !== false) {
      setTimeout(() => {
        layerMain.remove()
        if (obj.mask !== false) {
          const layerMask = document.getElementById('layerMaskId')
          layerMask.remove()
        }
      }, 2000)
    }
  },

  // 删除
  msgRemove: () => {
    if (document.getElementById('layerId') != null) {
      const layerMain = document.getElementById('layerId')
      layerMain.remove()
    }
    if (document.getElementById('layerMaskId') != null) {
      const layerMask = document.getElementById('layerMaskId')
      layerMask.remove()
    }
  }
}
